package com.scala.learn.sparkUDF

import java.lang

import org.apache.spark.sql.{DataFrame, Dataset, SparkSession}

/**
  * @Copyright: Shanghai Definesys Company.All rights reserved.
  * @Description:
  * @author: chuhaitao
  * @since: 2019/3/16 23:05
  * @history:
  *          1.2019/3/16 created by chuhaitao
  */
object UDAFDemo {

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder().master("local").appName("udaf")
      .getOrCreate()

    val data: Dataset[lang.Long] = spark.range(1, 10)

    data.show()
    data.createTempView("v1")

    val gc = new GeometricMean
    spark.udf.register("gc", gc)
    val frame: DataFrame = spark.sql("select gc(id) from v1 ")

    frame.show()
  }

}
